package com.hxzy.service.impl;

import com.hxzy.entity.UmsAdmin;
import com.hxzy.mapper.UmsAdminMapper;
import com.hxzy.service.UmsAdminService;
import com.hxzy.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class UmsAdminServiceImpl implements UmsAdminService {
    @Override
    public UmsAdmin selectByPrimaryKey(Long id) {
        UmsAdmin umsAdmin=null;
        try (SqlSession session= MybatisUtil.getSqlSessionFactory().openSession()){
            UmsAdminMapper mapper = session.getMapper(UmsAdminMapper.class);
            umsAdmin=mapper.selectByPrimaryKey(id);
        }
        return umsAdmin;
    }

    @Override
    public boolean insert(UmsAdmin record) {
        int count=0;
        try (SqlSession session= MybatisUtil.getSqlSessionFactory().openSession()){
            UmsAdminMapper mapper = session.getMapper(UmsAdminMapper.class);
            count=mapper.insert(record);
            session.commit();
        }
        return count>0;
    }

    @Override
    public boolean updateByPrimaryKey(UmsAdmin record) {
        int count=0;
        try (SqlSession session= MybatisUtil.getSqlSessionFactory().openSession()){
            UmsAdminMapper mapper = session.getMapper(UmsAdminMapper.class);
            count=mapper.updateByPrimaryKey(record);
            session.commit();
        }
        return count>0;
    }

    @Override
    public boolean updateByPrimaryKeySelective(UmsAdmin record) {
        int count=0;
        try (SqlSession session= MybatisUtil.getSqlSessionFactory().openSession()){
            UmsAdminMapper mapper = session.getMapper(UmsAdminMapper.class);
            count=mapper.updateByPrimaryKeySelective(record);
            session.commit();
        }
        return count>0;
    }

    @Override
    public List<UmsAdmin> search() {
        List<UmsAdmin> search=null;
        try (SqlSession session= MybatisUtil.getSqlSessionFactory().openSession()) {
            UmsAdminMapper mapper = session.getMapper(UmsAdminMapper.class);
            search = mapper.search();
            session.commit();
        }
        return search;
    }

    @Override
    public List<UmsAdmin> searchByCondition(UmsAdmin umsAdminm) {
        List<UmsAdmin> list;
        try (SqlSession session= MybatisUtil.getSqlSessionFactory().openSession()) {
            UmsAdminMapper mapper = session.getMapper(UmsAdminMapper.class);
            list = mapper.searchByCondition(umsAdminm);
        }
        return list;
    }
}
